//
//  UseForm.swift
//  learn-ios
//
//  Created by Dong on 2022/4/5.
//

import SwiftUI

struct UseForm: View {
    @State private var username: String = ""
    @State private var sex: Sex = .男
    @State private var isNotification:Bool = true
    @State private var feedback:String = "相对我们说的话: "
    

    enum Sex: String, CaseIterable, Identifiable {
        case 男, 女
        var id: Self { self }
    }

    var body: some View {
        Form {
            Section("个人信息") {
                TextField("姓名", text: $username)
                Picker("性别", selection: $sex) {
                    ForEach(Sex.allCases) { item in
                        Text(item.rawValue.description)
                    }
                }
            }
            
            Section("打扰"){
                Toggle("是否允许通知", isOn: $isNotification)
            }
            
            Section("反馈"){
                TextEditor(text: $feedback)
                    .frame(height:200)
            }
            
            Button {
                print("info: \(username) \(sex)")
                print("notification: \(isNotification)")
            } label: {
                Text("提交")
            }

        }
    }
}

struct UseForm_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            UseForm()
        }
    }
}
